package com.accompany.service.impl;

import com.accompany.entity.SkillTag;
import com.accompany.dao.SkillTagMapper;
import com.accompany.service.SkillTagService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 技能标签表 服务实现类
 * </p>
 *
 * @author DC
 * @since 2024-12-26
 */
@Slf4j
@Service
public class SkillTagServiceImpl extends ServiceImpl<SkillTagMapper, SkillTag> implements SkillTagService {

    @Autowired
    private SkillTagMapper skillTagMapper;

    /**
     * 分页查询技能标签列表
     *
     * @param page 页码
     * @param size 每页大小
     * @return 分页结果
     */
    @Override
    public Page<SkillTag> getPaginatedSkillTags(Integer page, Integer size) {
        try {
            log.info("分页查询技能标签列表，页码：{}, 每页大小：{}", page, size);
            Page<SkillTag> pageObj = new Page<>(page, size);
            Page<SkillTag> skillTagPage = baseMapper.selectPage(pageObj, null);
            skillTagPage.getRecords().forEach(item -> log.info(item.toString()));
            return skillTagPage;
        } catch (Exception e) {
            log.error("分页查询技能标签列表时发生错误，页码：{}, 每页大小：{}", page, size, e);
            throw e;
        }
    }

    /**
     * 获取所有技能标签列表
     *
     * @return 技能标签列表
     */
    @Override
    public List<SkillTag> getAllSkillTags() {
        try {
            log.info("获取所有技能标签列表");
            return skillTagMapper.selectList(null);
        } catch (Exception e) {
            log.error("获取所有技能标签列表时发生错误", e);
            throw e;
        }
    }

    /**
     * 获取单个技能标签信息
     *
     * @param id 技能标签ID
     * @return 技能标签对象
     */
    @Override
    public SkillTag getSkillTagById(Long id) {
        try {
            log.info("获取单个技能标签信息，技能标签ID：{}", id);
            return skillTagMapper.selectById(id);
        } catch (Exception e) {
            log.error("获取单个技能标签信息时发生错误，技能标签ID：{}", id, e);
            throw e;
        }
    }

    /**
     * 更新技能标签信息
     *
     * @param skillTag 技能标签信息
     */
    @Override
    @Transactional
    public void updateSkillTag(SkillTag skillTag) {
        try {
            log.info("更新技能标签信息，技能标签信息：{}", skillTag.toString());
            skillTagMapper.updateById(skillTag);
        } catch (Exception e) {
            log.error("更新技能标签信息时发生错误，技能标签信息：{}", skillTag.toString(), e);
            throw e;
        }
    }

    /**
     * 删除技能标签
     *
     * @param id 技能标签ID
     */
    @Override
    @Transactional
    public void deleteSkillTag(Long id) {
        try {
            log.info("删除技能标签，技能标签ID：{}", id);
            skillTagMapper.deleteById(id);
        } catch (Exception e) {
            log.error("删除技能标签时发生错误，技能标签ID：{}", id, e);
            throw e;
        }
    }

    /**
     * 创建技能标签
     *
     * @param skillTag 技能标签信息
     */
    @Override
    @Transactional
    public void createSkillTag(SkillTag skillTag) {
        try {
            log.info("创建技能标签：{}", skillTag.toString());
            skillTagMapper.insert(skillTag);
        } catch (Exception e) {
            log.error("创建技能标签时发生错误，技能标签信息：{}", skillTag.toString(), e);
            throw e;
        }
    }
}